home *** CD-ROM | disk | FTP | other *** search
- /* $VER: UpdateCT.rexx 01.00 (29.09.1993) © S.Sürken */
- /* */
- /* rx UpdateCT <CD-FILE> <OLD_CT-FILE> <NEW_CT-FILE> */
- /* */
- /* Updates a CT file referring to a given translation file. */
- /* */
- /* That means: */
- /* + Creating new head (update version & codeset) */
- /* (for that, the cd must have a head as comment, see example file) */
- /* + Adding new strings (if there) to the translation file */
- /* (these strings get the default, preceded by "(*) ") */
- /* + Deleting omitted strings (if there) from the translation file */
- /* + Updating the default texts (as comments) of existing strings */
- /* if changed */
- /* + Providing the same order as in the description file */
- /* */
- /* :-( only normal codesetting allowed (no MSG_XXX (code/X/X)) */
- /* */
-
-
- /* INITIALIZATION */
- toTranslateStr = "(*)"
-
- cdName = WORD(ARG(1), 1)
- ctName = WORD(ARG(1), 2)
- newCTName = WORD(ARG(1), 3)
- /* END INITIALIZATION */
-
- /* CHECK FOR SAME NAMES (ELSE INPUTS WOULD BE DELETED...) */
- IF (COMPARE(UPPER(cdName), UPPER(newCTName)) = 0) | (COMPARE(UPPER(ctName), UPPER(newCTName)) = 0)
- THEN DO
- SAY "Error: Input CD or CT name equals output CT file."; EXIT 10 /* error cancel */
- END
- /* END CHECK FOR SAME NAMES */
-
- /* CONTINUE WITH INIT? */
- SAY "Input CD-File: "cdName
- SAY "Input CT-File: "ctName
- SAY "New CT-File: "newCTName
-
- SAY "Sure to continue? "
- IF UPPER(READCH(STDIN, 1)) ~= "Y"
- THEN DO
- SAY "Cancelled."; EXIT 10 /* user cancel */
- END
- /* END CONTINUE WITH INIT? */
-
-
- /* OPEN FILES */
- IF OPEN(cd, cdName, read) & OPEN(ct, ctName, read) & OPEN(newCT, newCTName, write)
- THEN SAY "Files correctly opened."
- ELSE DO
- SAY "File error."; EXIT 10 /* error cancel */
- END
- /* END OPEN FILES */
-
- /* WRITE CT-HEAD */
- CALL WRITELN(newCT, "; Updatet catalog translation file ("DATE()")")
- CALL WRITELN(newCT, "; UpdateCT is © S.Sürken")
- CALL WRITELN(newCT, DELSTR(Find(cd, "; ## version"), 1, 2)) /* version from cd */
- CALL WRITELN(newCT, DELSTR(Find(cd, "; ## codeset"), 1, 2)) /* codeset from cd */
- CALL WRITELN(newCT, Find(ct, "## language")) /* language from old ct */
- CALL WRITELN(newCT, ";")
- /* END WRITE CT-HEAD */
-
- /* CREATE CLIPLIST (all found tokens of old ct file) */
- SAY "Creating clipboard list..."
- DO
- SEEK(ct, 0, 'B') /* start of file */
- DO WHILE ~EOF(ct)
- id = READLN(ct)
-
- IF (Kind(id) = 2) & (COMPARE(id, "") ~= 0)
- THEN DO
- SETCLIP(id, READLN(ct))
- END
-
- END
- END
- /* END CREATE CLIPLIST */
-
- /* GENERATE NEW CT */
- toTranslate = 0 /* amount of strings to translate */
- code = -1 /* current code */
- DO WHILE ~EOF(cd)
- line = READLN(cd)
-
- IF Kind(line) = 2
- THEN DO
- id = WORD(line, 1)
-
- cdText = READLN(cd)
-
- IF COMPARE(id, "") ~= 0
- THEN DO
- code = code+1
- SAY "Updating Code "code": "id
-
- CALL WRITELN(newCT, id)
- CALL WRITELN(newCT, GetTranslation(id, cdText))
- CALL WRITELN(newCT, "; "cdText)
- CALL WRITELN(newCT, ";")
-
- /* remove translation from clip list */
- SETCLIP(id, "")
- END
- END
- END
- /* END GENERATE NEW CT */
-
- /* OUT STATUS */
- SAY ""
- SAY "Codes from 0 to "code", altogether "code+1" Strings."
- SAY "Found "toTranslate" strings to be translated."
- SAY ""
- /* END OUT STATUS */
-
- EXIT 0 /* done exit */
-
-
- /* MACROS */
-
- Kind: SELECT
- WHEN POS("#", ARG(1)) = 1
- THEN RETURN 0 /* a command */
- WHEN POS(";", ARG(1)) = 1
- THEN RETURN 1 /* a comment */
- OTHERWISE RETURN 2 /* a relevant line */
- END
-
-
- /* Find(file, id) --> line with id */
- Find: DO
- SEEK(ARG(1), 0, 'B') /* start of file */
- DO WHILE ~EOF(ARG(1))
- line = READLN(ARG(1))
- IF POS(ARG(2), line) = 1
- THEN RETURN line
- END
- RETURN ""
- END
-
- /* GetTranslation(id, original) --> translation */
- GetTranslation: DO
- translation = GETCLIP(ARG(1))
- IF COMPARE(translation, "") = 0
- THEN /* no translation found */
- DO
- toTranslate = toTranslate+1
- translation = toTranslateStr ARG(2)
- END
- RETURN translation
- END
-
- /* END MACROS */
-